import api from '../../api/index'

Page({

  data: {
    key: '',
    contests: []
  },

  blur: function(e) {
    var key = e.detail.value.trim();
    if (key == this.data.key) return;
    this.setData({key})
    
    if (key.length > 0) {
      wx.showNavigationBarLoading()
      api.contest.search({key})
        .then(res => {
          this.setData({ contests: res.data})
          wx.hideNavigationBarLoading()
          console.log(this.data.contests)
        })
    } else {
      this.setData({ contests: []})
    }
  }

})